﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace IiiToolkitMain.Controls
{
    public partial class CapturePicture : UserControl
    {
        //注册事件
        public event CapturePictureClick OnPictureClick;
        public CapturePicture()
        {
            InitializeComponent();
        }

        private string PicturePath;
        public DateTime CreateTime { get; set; }

        public void SetPicture(string path)
        {
            try
            {
                System.Net.WebRequest webreq = System.Net.WebRequest.Create(path);
                System.Net.WebResponse webres = webreq.GetResponse();
                using (System.IO.Stream stream = webres.GetResponseStream())
                {
                    
                    var image = Image.FromStream(stream);
                    this.pictureBox1.Image = image;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            //this.PicturePath = path;
            //this.pictureBox1.Image = Image.FromFile(path);
            this.pictureBox1.ImageLocation = path;
            pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {
            if (OnPictureClick != null)
            {
                OnPictureClick(this.pictureBox1, new CapturePictureEventArgs(PicturePath));
            }
        }
    }
}
